package com.servlet;

import com.bean.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/regist.do")
public class RegistServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //解决响应中文乱码
        resp.setContentType("text/html;charset=utf-8");

        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String gender = req.getParameter("gender");
        //对于多选框等 使用 getParameterValues
        String[] hobby = req.getParameterValues("hobby");
        String province = req.getParameter("province");
        String introduction = req.getParameter("introduction");

        User user = new User(username, password, gender, hobby, province, introduction);
        System.out.println(user);
        //获取响应的字符输出流
//        resp.getWriter().write("<h1>注册成功</h1>");
        resp.sendRedirect("./login.html");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
